<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;
use think\Db;

/**
 * 文章类合并控制器
 */
class Merge extends AdminBase
{
    public $articleType = [
        1 =>"首页展示",
        2 =>"项目案例-环保",
        3 =>"项目案例-能源",
        4 =>"项目案例-科技",
        5 =>"集团概况-公司简介",
        6 =>"集团概况-精英团队",
        7 =>"集团概况-发展历程",
        8 =>"服务范围-科技",
        9 =>"服务范围-建设",
        10=>"服务范围-信息",
        11=>"服务范围-网络资源",
        12=>"服务范围-资产管理",
        13=>"服务范围-广告",
        14=>"咨询中心",
        15=>"联系我们",
        16=>"招贤纳士",
    ];
    
    
    /**
     * 首页 模块列表
     */
    public function homePageList()
    {
        
        $this->commonList(1);
        
        return $this->fetch('article_list');
    }
    
    
    /**
     * 首页 模块文章添加
     */
    public function homePageAdd(){
        
    }
    
    
    /**
     * 项目案例-环保
     */
    public function environment()
    {
        
        $this->commonEdit(2,'environment');
        
        return $this->fetch('article_edit');
    }
    
    
    /**
     * 项目案例-能源
     */
    public function energy()
    {
        
        $this->commonEdit(3,'energy');
       
        return $this->fetch('article_edit');
    }
    
    
    /**
     * 项目案例-科技
     */
    public function technology()
    {
        
        $this->commonEdit(4,'technology');
       
        return $this->fetch('article_edit');
    }
     
    
    /**
     * 集团概况-公司简介
     */
    public function introduction()
    {
        
        $this->commonEdit(5,'introduction');
       
        return $this->fetch('article_edit');
    }
    
    
    /**
     * 集团概况-精英团队
     */
    public function eliteTeam()
    {
        
        $this->commonEdit(6,'eliteteam');
       
        return $this->fetch('article_edit');
    }
    
    
    /**
     * 集团概况-精英团队
     */
    public function experience()
    {
        
        $this->commonEdit(7,'experience');
       
        return $this->fetch('article_edit');
    }
    
    
    /**
     * 资讯中心-资讯列表
     */
      public function infoList()
    {
        
        $this->commonList(14);
       
        return $this->fetch('info_list');
    }
    
    
    /**
     * 资讯中心-添加资讯
     */
    public function infoAdd()
    {
        $this->commonEdit(14,'infoList');
        
        return $this->fetch('article_edit');
    }
    
        
    /**
     * 通用文章列表获取方法
     * @param type $type 文章类型
     * @return type
     */
     public function commonList($type)
    {
         
        $where['a.category_id'] = 14;
        
        $this->assign('list', $this->logicArticle->getArticleList($where, 'a.*,m.nickname,c.name as category_name', 'a.create_time desc'));
    }
    
    
    /**
     * 通用获取文章编辑信息
     * @param type $type 文章类型
     * @return type
     */
    public function commonEdit($type,$url)
    {
       
        $this->articleCommon($type,$url);

        if(empty($this->param['id'])){
            
            $article_id = $this->getIdByCategoryId($type);
            
        }else{
            
            $article_id = $this->param['id'];
        }

        $info = $this->logicArticle->getArticleInfo(['a.id' => $article_id], 'a.*,m.nickname,c.name as category_name');

        !empty($info) && $info['img_ids_array'] = str2arr($info['img_ids']);
        
        $this->assign('info', $info);
    }
    
    
    /**
     * 文章添加与编辑通用方法
     */
    public function articleCommon($type,$url)
    {
        
        IS_POST && $this->jump($this->logicArticle->articleEdit($this->param,$type,$url));
    }
    
    
    /**
     * 数据状态设置
     */
    public function setStatus()
    {
        
        $this->jump($this->logicAdminBase->setStatus('Article', $this->param));
    }
    
    
    /**
     * 通过分类获取文章ID
     */
    public function getIdByCategoryId($type)
    {
        
        $article = Db::query('select id from rb_article where category_id=?',[$type]);
        
        $articleId = $article?$article[0]['id']:0;
        
        return $articleId;
    }
}
